package com.office.personalOffice.nameCard.personalNameCard.control;



import com.office.personalOffice.nameCard.nameCardList.pojo.OaNamecard;
import com.office.personalOffice.nameCard.nameCardList.pojo.OaNamecardlist;
import com.office.personalOffice.nameCard.personalNameCard.pojo.TbPosition;
import com.office.personalOffice.nameCard.personalNameCard.service.impl.PNCService;
import com.office.personalOffice.personalInfo.model.TbStaff;
import com.office.personalOffice.personalInfoQuery.model.TbDept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @project_name: OA
 * @description:
 * @author: LaoWang
 * @date: 2022/11/1 18:34
 */

@RequestMapping("/personalNameCard")
@Controller
public class personalNameCardControl {

    @Autowired
    private PNCService service;



    //拿取当前用户所有名片
    @RequestMapping("/getNameCardList")
    @ResponseBody
    public List<OaNamecard> getOaNamecardlist(String maillistId, HttpSession session){

        TbStaff staff1 = (TbStaff) session.getAttribute("loginUser");
        maillistId=staff1.getId().toString();
        List<OaNamecard> allNamecardByMaillistId = service.getAllNamecardByMaillistId(maillistId);
        allNamecardByMaillistId.get(0).setUserId(maillistId);
        return allNamecardByMaillistId;

    }



    //拿取所有用户名片夹分类
    @RequestMapping("/getAllNameCardList")
    @ResponseBody
    public List<OaNamecardlist>  getAllNamecard(){
        return service.getAllNamecard();
    }




    //添加名片验证（每个用户的所拥有的每个名片只能存放在一个名片夹类中）
    @RequestMapping("/NameCardYZ")
    @ResponseBody
    public String NameCardYZ(OaNamecardlist oaNamecardlist,HttpSession session){
        return service.NameCardYZ(oaNamecardlist, session);
    }




    //添加名片
    @RequestMapping("/addNameCard")
    @ResponseBody
    public String addNameCard(OaNamecardlist oaNamecardlist,HttpSession session){
        return service.addOaNamecardlist(oaNamecardlist, session);
    }


    //删除名片
    @RequestMapping("/delete/{deleteID}")
    @ResponseBody
    public String deleteNameCard(@PathVariable String deleteID, OaNamecard oaNamecard){
        oaNamecard.setNamecardEmpId(deleteID);
        Integer integer = service.deleteNameCard(oaNamecard);
        if(integer==1){
            return "true";
        }else {
            return "false";
        }
    }


    //根据id查询名片信息即员工信息
    @RequestMapping("/query")
    @ResponseBody
    public com.office.personalOffice.personalInfo.model.TbStaff queryNameCard(@RequestBody com.office.personalOffice.personalInfo.model.TbStaff   tbStaff){
        return service.queryNameCard(tbStaff);
    }


    //拿取所有的部门信息
    @RequestMapping("/getAllDept")
    @ResponseBody
    public List<TbDept> getAllDept(){
        return service.getAllDept();
    }



    //获取所有职位
    @RequestMapping("/getPosition")
    @ResponseBody
    public List<TbPosition>  getAllTbPosition(TbPosition tbPosition){
        return service.getAllTbPosition(tbPosition);
    }



    //修改名片
    @RequestMapping("/update")
    @ResponseBody
    public String updateNameCard(@RequestBody com.office.personalOffice.personalInfo.model.TbStaff   tbStaff){
        return service.updateNameCard(tbStaff);
    }



    //移动名片验证
    @RequestMapping("/nameCardListYZ")
    @ResponseBody
    public String nameCardListYZ(@RequestBody OaNamecardlist oaNamecardlist,HttpSession session){
        return service.nameCardListYZ(oaNamecardlist,session);
    }



    //移动名片
    @RequestMapping("/nameCardListRemove")
    @ResponseBody
    public String nameCardListRemove(@RequestBody OaNamecardlist oaNamecardlist,HttpSession session){
        return service.nameCardListRemove(oaNamecardlist,session);
    }


}
